/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spring;

import engine.Player;
import engine.Singleton;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import server.OneForAllServer;

/**
 *
 * @author Alexx
 */
public class SingleServer extends Thread implements IServer
{
    static final int PORT = 8888;
    @Override
    public void run()
    {
        OneForAllServer clients = new OneForAllServer();
        clients.start();
        ServerSocket s = null;
        try {
            s = new ServerSocket(PORT);
        } catch (IOException ex) {
            Logger.getLogger(SingleServer.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Server For One Started");
        Singleton.getInstance();
        List<Player> c = Singleton.clients;
        
        try
        {
            while (true)
            {
                Socket socket = s.accept();
                Player p = new Player(clients, socket);
                c.add(p);
                
                    // тут новый player
            }
        }
        catch (IOException ex) {
            Logger.getLogger(SingleServer.class.getName()).log(Level.SEVERE, null, ex);
        }        finally
        {
            try {
                s.close();
            } catch (IOException ex) {
                Logger.getLogger(SingleServer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
